Implement streaming#75
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
wolffiex
left a comment
There was a problem hiding this comment.
Code Review
Great implementation of streaming capabilities! The bidirectional streaming API is well-designed with clear separation between query() for simple use cases and ClaudeSDKClient for interactive sessions.
Key strengths:
- Clean API design with two distinct modes
- Good async/await patterns throughout
- Comprehensive test coverage
- Helpful examples
Areas for improvement:
1. JSON Error Handling
- JSON parsing errors are silently ignored in subprocess_cli.py:294
- No error handling for missing keys in message_parser.py
- Inconsistent use of .get() vs direct key access
2. Parameter Naming Inconsistencies
connect()uses 'prompt' whilesend_message()uses 'content'- 'prompt' is confusing for AsyncIterable of messages
- Should be consistent across the API
3. Resource Management
- Hardcoded timeouts (30s for control requests)
- Fixed memory limits not configurable
- No backpressure handling
4. API Clarity
receive_response()stopping behavior could be clearersend_message()only accepts strings vs structured messages inconnect()
Overall, this is a solid foundation that would benefit from addressing these consistency and robustness issues.
|
Addressing feedback:
The existing code in subprocess_cli.py:294 tries to decode a buffer until it encounters a valid JSON object, so silently ignoring JSON decoding errors is intentional. This PR maintains this behavior for backward compatibility.
Added KeyError checking in message_parser.py to match the Typescript SDK. All direct key accesses are now wrapped.
Renamed
Fixed
Let's address this in a separate PR. This PR should focus on providing a new way to feed input into Claude Code SDK via streaming. I believe the "fixed memory limits" and "backpressure" issues refer to the output stream, which this PR should ideally not touch.
Fixed
Fixed |
query()out ofsrc/claude_code_sdk/__init__.pyparse_message()out ofsrc/claude_code_sdk/_internal/client.pysrc/claude_code_sdk/client.py